package com.demo.springboot;

import org.springframework.context.annotation.AnnotationConfigApplicationContext;

public class AnnotationScan2 {

    public static void main(String[] args) {
        AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext(AnnotationScanConfig.class);

        System.out.println("通过类型来获取Bean:::::" + applicationContext.getBean(MyBean.class));
        System.out.println("通过名字来获取Bean:::::" + applicationContext.getBean("MyBean"));
        System.out.println("通过类型来获取Bean:::::" + applicationContext.getBean(RunableFactoryBean.class));
        System.out.println("通过类型来获取Bean:::::" + applicationContext.getBean(Jeep.class));
        System.out.println("通过名字来获取Bean:::::" + applicationContext.getBean("createFactoryBean"));
        System.out.println("通过名字来获取Bean:::::" + applicationContext.getBean("&createFactoryBean"));
        System.out.println("通过类型来获取Bean:::::" + applicationContext.getBean(Car.class));
        System.out.println("通过类型来获取Bean:::::" + applicationContext.getBean(Cat.class));
        System.out.println("通过类型来获取Bean:::::" + applicationContext.getBean(Dog.class));
        System.out.println("通过类型来获取Bean:::::" + applicationContext.getBean(Animal.class));
        System.out.println("通过类型来获取Bean:::::" + applicationContext.getBean(User.class));
        System.out.println("通过类型来获取Bean:::::" + applicationContext.getBeansOfType(User.class));
        System.out.println("通过名字来获取Bean:::::" + applicationContext.getBean("myUser"));
        //System.out.println("通过类型来获取Bean:::::" + applicationContext.getBean(UserDao.class));
        System.out.println("通过类型来获取Bean:::::" + applicationContext.getBean(UserService.class));
        System.out.println("通过类型来获取Bean:::::" + applicationContext.getBean(UserController.class));

        User user = applicationContext.getBean("myUser", User.class);
        System.out.println("依赖注入demo：" + user);

        applicationContext.close();
    }
}
